package cn.gorit.content.controller;

import cn.gorit.common.lang.Result;
import cn.gorit.content.service.LikeService;
import cn.gorit.entity.content.Like;
import cn.gorit.entity.user.User;
import cn.gorit.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version v1.0
 * @Classname LikeController
 * @Description 点赞功能
 * @Author CodingGorit
 * @Created on 2021/4/5 20:34
 * @IDLE IntelliJ IDEA
 **/
@RestController
@RequestMapping("/api/v1/front/like")
public class LikeController {

    @Autowired
    LikeService service;

    // 添加点赞状态 【前端检查是否有数据】
    @PostMapping
    public Result<Object> addLike(@RequestBody Like like) {
        return service.insertLike(like);
    }

    // 修改点赞状态
    @PutMapping
    public Result<Object> updateLike(@RequestBody Like like) {
        return service.updateLike(like);
    }

    // 查询点赞的具体信息  【后期需要 join 查询，查询用户的具体信息】
    @GetMapping("/user/{userId}/likeId/{likeId}")
    public Result<Like> getLikeById(@PathVariable("userId") String userId, @PathVariable("likeId") String likeId) {
        return service.getLikeByUserIdAndBlogId(userId,likeId);
    }

    // 分页查询用户列表
    @PostMapping("/list/page")
    public Result<Page<Like>> getLikeByList(@RequestBody Page<Like> page) {
        return service.getLikeList(page);
    }

    @GetMapping("/user/detail/{userId}")
    public Result<User> getRPCUserDetail(@PathVariable("userId") String userId) {
        return service.getUserByUserId(userId);
    }
}
